import request from '../utils/request'

// 管理员登录
export function adminLogin(adminNo, password) {
  return request({
    url: '/admin/login',
    method: 'post',
    data: { adminNo, password }
  })
}

// 分页查询管理员列表
export function getAdminList(params) {
  // 仅发送有值的查询参数，避免后端把占位值当作条件
  const requestParams = {
    pageNum: params.pageNum || 1,
    pageSize: params.pageSize || 10
  }
  if (params.adminNo) requestParams.adminNo = params.adminNo
  if (params.adminName) requestParams.adminName = params.adminName
  if (params.adminRole) requestParams.adminRole = params.adminRole
  if (params.adminStatus !== undefined && params.adminStatus !== null && params.adminStatus !== '') {
    requestParams.adminStatus = params.adminStatus
  }
  
  return request({
    url: '/admin/listPage',
    method: 'get',
    params: requestParams
  })
}

// 根据id查询管理员详情
export function getAdminDetail(id) {
  return request({
    url: '/admin/select',
    method: 'get',
    params: { id }
  })
}

// 新增管理员
export function addAdmin(data) {
  return request({
    url: '/admin/save',
    method: 'post',
    data
  })
}

// 编辑管理员
export function updateAdmin(data) {
  return request({
    url: '/admin/update',
    method: 'put',
    data
  })
}

// 根据管理员账号查询
export function getAdminByNo(adminNo) {
  return request({
    url: `/admin/no/${adminNo}`,
    method: 'get'
  })
}

// 删除管理员（通过ID）
export function deleteAdmin(id) {
  return request({
    url: '/admin/delete',
    method: 'delete',
    params: { id }
  })
}

// 删除管理员（通过账号）
export function deleteAdminByNo(adminNo) {
  return request({
    url: '/admin/deleteByNo',
    method: 'delete',
    params: { adminNo }
  })
}

// 批量删除管理员
export function deleteAdmins(ids) {
  return request({
    url: '/admin/batch',
    method: 'delete',
    data: ids
  })
}

// 获取系统统计数据
export function getSystemStats() {
  return request({
    url: '/admin/stats',
    method: 'get'
  })
}
